<?php
 
include './db/database.php';
include './controler/userControler.php';
  

$routes[] = array(
    'url' => "rest/login",
    'method' => 'GET',
    'controler' => 'UserControler',
    'action' => 'login'
);

 
function match($str, $end) {
    $size = strlen($end);
    return((substr($str, strlen($str) - $size, $size)) === $end);
} 

$url = $_REQUEST['action'];    
 
foreach ($routes as $route) {  
    if (match($url, $route['url'])) {
        if ($_SERVER['REQUEST_METHOD'] == $route['method']) { 
            $controler = new $route['controler']();  
            $r = $controler->$route['action']($_REQUEST);
            echo $r;
            return;
        }
    }
};
var_dump($_REQUEST); 
echo json_encode(array( "status" => 'KO', "exception" => "No route found for " . $url . " and Method " . $_SERVER['REQUEST_METHOD']));


